#pragma once
#include "../stdafx.h"
#include <vector>
using namespace std;
template<typename T>
	class Manager
	{
	public:
		Manager(char* fname)
		{
			char logname[256];
			strcpy_s(logname,256,fname);
			strcat_s(logname,256,".log");
			m_fp=fopen(logname,"w+");
			m_data.clear();
			m_curID=0;
		}
		~Manager(void)
		{
			fclose(m_fp);
		}

		//virtual bool AddObj(int32,char*,void*)=0;
		virtual void Log()=0;
		//virtual bool DelObj(uint32);
		
		virtual T* GetObj(int32 id)
		{
			for(uint32 i=0;i<m_data.size();i++)
			{
				if(m_data[i].GetID()==id)
					return &m_data[i];
			}
			return NULL;
        }

        typedef bool(*FUNC)(T,boost::any);
        void foreach(FUNC func,boost::any any)
        {
            for(vector<T>::iterator iter=m_data.begin();iter<m_data.end();iter++)
            {
                if(func(*iter,any))
                    return;
            }
        }

		inline virtual void _log(char* msg)
		{
			fwrite(msg,strlen(msg),1,m_fp);
		}

		inline virtual void Clear()
		{
			m_data.clear();
		}

        void AddObj(T data)
        {
            data.SetID(m_curID++);
            m_data.push_back(data);
        }
    private:
		vector<T> m_data;
		int32 m_curID;
		FILE* m_fp;
	};